/**  
* @Title: OrderIdUtil.java  
* @Package com.chuan.base.util  
* @Description: TODO(生成唯一订单号)  
* @author Mr.zhao  
* @date 2018年6月11日  
* @version V1.0  
*/
package com.chuan.base.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Mr.zhao
 * @date 2018年6月11日
 *
 */
public class OrderIdUtil {

	private static Integer ORDERINDEX = 100;
//	public static String createOrderId() {
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//		String newDate = sdf.format(new Date());
//		String result = "";
//		Random random = new Random();
//		for (int i = 0; i < 3; i++) {
//			result += random.nextInt(10);
//		}
//		return newDate + result;
//	}
	public synchronized static String createOrderId(){
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		String orderId = sdf.format(date);
		if(ORDERINDEX > 99) ORDERINDEX = 0;
		orderId = orderId + (ORDERINDEX > 9 ? ORDERINDEX : ("0" + ORDERINDEX));
		ORDERINDEX++;
		return orderId;
	}
}
